package com.example.eshop_ssm.service.impl;

import com.example.eshop_ssm.entity.AdImgInfo;
import com.example.eshop_ssm.entity.NewsInfo;
import com.example.eshop_ssm.mapper.AdMapper;
import com.example.eshop_ssm.service.AdService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AdServiceImpl implements AdService {

    @Autowired
    private AdMapper adMapper;

    @Override
    public List<NewsInfo> selectNews(Integer page, Integer tiao) {
        Map<String, Object> map = new HashMap<>();
        map.put("page", page);
        map.put("tiao", tiao);


        return adMapper.selectNews(map);
    }

    @Override
    public int countNews() {
        return adMapper.countNews();
    }

    @Override
    public boolean addNews(String news_title, Integer book_id) {
        Map<String, Object> map = new HashMap<>();
        map.put("news_title", news_title);
        map.put("book_id", book_id);

        return adMapper.addNews(map);
    }

    @Override
    public boolean delNews(Integer news_id) {
        return adMapper.delNews(news_id);
    }

    @Override
    public NewsInfo selectOneNew(Integer news_id) {
        return adMapper.selectOneNew(news_id);
    }

    @Override
    public boolean updateNews(Integer news_id, String news_title, Integer book_id) {
        Map<String, Object> map = new HashMap<>();
        map.put("news_id", news_id);
        map.put("news_title", news_title);
        map.put("book_id", book_id);

        return adMapper.updateNews(map);
    }

    @Override
    public boolean inseImg(String ad_img, Integer book_id) {
        Map<String, Object> map = new HashMap<>();
        map.put("ad_img", ad_img);
        map.put("book_id", book_id);


        return adMapper.inseImg(map);

    }

    @Override
    public List<AdImgInfo> selectImg() {
        return adMapper.selectImg();
    }

    @Override
    public boolean deleteImg(Integer ad_id) {
        return adMapper.deleteImg(ad_id);
    }
}
